
export default class MockStore {
  constructor(name) {
    this.name = name;
    const key = name + '_inited';
    if (!localStorage.getItem(key)) {
      this.initialize();
      localStorage.setItem(key, true);
    }
  }

  get(key) {
    const k = this.name + key;
    return localStorage.getItem(k);
  }
  set(key, value) {
    const k = this.name + key;
    localStorage.setItem(k, value);
  }

  getJson(key) {
    const k = this.name + key;
    const value = localStorage.getItem(k);
    return value && JSON.parse(value);
  }
  setJson(key, value) {
    const k = this.name + key;
    value = value && JSON.stringify(value);
    localStorage.setItem(k, value);
  }

  readFile(key) {
    const fkey = this.name + '_FILE_' + key;
    return localStorage.getItem(fkey);
  }
  writeFile(key, content) {
    const fkey = this.name + '_FILE_' + key;
    localStorage.setItem(fkey, content);
  }

  initialize() {
    // init data when first startup
  }
}